package com.web;

import java.io.IOException;
import java.util.ArrayList;

import javax.servlet.RequestDispatcher;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import bizlogic.LeaveManager;

import model.LeaveDTO;
import model.UserDTO;

/* ************************************************************** */
/* Servlet implementation to load all leave data by userid    */
/* Added by : Suganthi V Subramaniam                              */
/* *************************************************************  */
public class LoadLeaveHistoryServlet extends HttpServlet {
	private static final long serialVersionUID = 1L;

	/**
	 * @see HttpServlet#HttpServlet()
	 */
	public LoadLeaveHistoryServlet() {
		super();
		// TODO Auto-generated constructor stub
	}

	/**
	 * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse
	 *      response)
	 */
	protected void doGet(HttpServletRequest request,
			HttpServletResponse response) throws ServletException, IOException {
		doProcess(request, response);
	}

	/**
	 * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse
	 *      response)
	 */
	protected void doPost(HttpServletRequest request,
			HttpServletResponse response) throws ServletException, IOException {
		doProcess(request, response);
	}

	private void doProcess(HttpServletRequest request,
			HttpServletResponse response) throws ServletException, IOException {

		UserDTO us = (UserDTO) request.getSession().getAttribute("user");
		String id = us.getId().toString();

		LeaveManager lm = new LeaveManager();
		ArrayList<LeaveDTO> leavelist = lm.findAllLeaveByUser(id);

		request.setAttribute("leavelist", leavelist);
		RequestDispatcher rd = request
				.getRequestDispatcher("/ViewPersonalLeaveHistory.jsp");
		rd.forward(request, response);

	}

}
